package online.siwu.memorycards


import android.app.Activity
import android.content.Intent
import android.content.pm.ActivityInfo
import android.util.Log
import android.view.Window
import android.view.WindowManager.LayoutParams
import android.widget.Toast

/**
 * Created on 2017/5/29.
 * Extend.kt
 */
class Extend

//1全屏、2标题栏、3横屏or竖屏。 在setContentView()之前调用。
fun Activity.setWindow(fullScreen: Boolean = false, actionBar: Boolean = true, orientation: Int = 0) {
    if (fullScreen)
        window.setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN)

    if (!actionBar)
        requestWindowFeature(Window.FEATURE_NO_TITLE)

    when (orientation) {
        1 -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        2 -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    }
}

// 1. Activity跳转。 2. 默认true:销毁this； false:保留this，可以返回。 3. 内联。
inline fun <reified activity : Activity> Activity.gotoActivity(finish: Boolean = true) {
    startActivity(Intent(this, activity::class.java))
    if (finish) finish()
}

// Toast的简化
fun Activity.toast(msg: String, isLong: Boolean = false) {
    if (isLong)
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show()
    Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
}

// Log的简化
fun Activity.log(msg: String, tag: String = "AUTO") {
    Log.i(tag, msg)
}

